package com.hexus.eve.actions;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.hexus.eve.entities.Race;
import com.hexus.eve.utils.TranslationUtils;
import com.opensymphony.xwork2.ActionSupport;

public class RaceInfo extends ActionSupport{
	private static final long serialVersionUID = 1L;
	
	private Integer id;
	private Race race;
	private Logger logger = Logger.getLogger(RaceInfo.class);;
	
	@Autowired
	private TranslationUtils translationUtils;
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public String execute() {
		String result = SUCCESS;
		Session session = sessionFactory.openSession();
		try {
			race = (Race) session.load(Race.class, getId());
			session.lock(race, LockMode.NONE);
			if (race == null) {
				if(logger.isInfoEnabled())
					logger.info("Race is null");
				result = NONE;
			} else {
				translationUtils.translate(race, getLocale());
			}

		} catch (HibernateException he) {
			System.out.println(he.getMessage());
			he.printStackTrace();
			result = NONE;
		}
		session.close();
		return result;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Race getRace() {
		return race;
	}

	public void setRace(Race race) {
		this.race = race;
	}
}